<template>
  <common-list>
    <common-table slot="content" v-loading="loading" :data="list" @selection-change="handleSelectionChange">
      <!--<el-table-column type="selection" width="55" align="left" />-->

      <el-table-column label="策略名称" align="left">
        <template slot-scope="{row}">{{ row.ruleName }}</template>
      </el-table-column>

      <el-table-column label="长度范围" align="left">
        <template slot-scope="{row}">{{ row.minLength + '-' + row.maxLength }}</template>
      </el-table-column>

      <el-table-column label="必须包含字符" align="left">
        <template slot-scope="{row}">
          <!--{{ row.firstIsUpper==0?'首字母大写、':"" }}
          {{ row.hasLower==0?'小写字母、':"" }}
          {{ row.hasNumber==0?'数字、':"" }}
          {{ row.hasSpecial==0?'特殊字符、':"" }}
          {{ row.hasUpper==0?'大写字母、':"" }}-->
          <div v-if="row.firstIsUpper || row.firstIsUpper == 0">
            首字母大写{{ (row.firstIsUpper || row.firstIsUpper == 0) ? firstIsUpper[row.firstIsUpper] : '无' }}
          </div>
          <div v-if="row.hasLower || row.hasLower == 0">
            小写字母{{ (row.hasLower || row.hasLower == 0) ? showTextRule[row.hasLower] : '无' }}
          </div>
          <div v-if="row.hasNumber || row.hasNumber == 0">
            数字{{ (row.hasNumber || row.hasNumber == 0) ? showTextRule[row.hasNumber] : '无' }}
          </div>
          <div v-if="row.hasSpecial || row.hasSpecial == 0">
            特殊字符{{ (row.hasSpecial || row.hasSpecial == 0) ? showTextRule[row.hasSpecial] : '无' }}
          </div>
          <div v-if="row.hasUpper || row.hasUpper == 0">
            大写字母{{ (row.hasUpper || row.hasUpper == 0) ? showTextRule[row.hasUpper] : '无' }}
          </div>
        </template>
      </el-table-column>

      <el-table-column label="特殊字符范围" align="left" prop="characters">
        <template slot-scope="{row}">{{ row.characters }}</template>
      </el-table-column>

      <!-- <el-table-column label="弱密码校验" align="left">
        <template slot-scope="{row}">
          <el-tag type="success" v-if="row.pwdHistroyNumberState == 0">校验</el-tag>
          <el-tag type="danger" v-else>未校验</el-tag>
        </template>
      </el-table-column> -->

      <el-table-column label="有效期" align="left">
        <template slot-scope="{row}">{{ row.validDays + '天' }}</template>
      </el-table-column>

      <el-table-column label="过期提醒" align="left">
        <template slot-scope="{row}">{{ '过期前' + row.notifyDays + '天' }}</template>
      </el-table-column>

      <el-table-column label="操作" align="left" width="52">
        <template slot-scope="{row}">
          <el-button type="text" @click="edit(row)" v-hasPermi="['system:pwdrule:updatePwdRule']">编辑</el-button>
        </template>
      </el-table-column>
    </common-table>

    <pagination slot="pagination" v-show="total>0" :total="total" :page.sync="query.pageNum"
                :limit.sync="query.pageSize" @pagination="getList"/>
    <!-- 列表 end -->
    <editDialog ref="editDialog" @refresh="getList"/>
  </common-list>
</template>

<script>
import { pwdrule_queryPageList } from '@/api/management/configure/index.js'
import editDialog from './components/passDialog'
import BaseList from '@/mixins/BaseList'

export default {
  components: { editDialog },
  mixins: [BaseList],
  props: {},
  data() {
    return {
      total: 1, // 总条数
      loading: false, // table 加载中
      list: [], // 数据列
      selectionIds: '', // 列表选中数据id
      single: true, // 非单个禁用
      multiple: true, // 非多个禁用
      query: {
        pageNum: 1,
        pageSize: 10
      }, // 查询条件
      showTextRule: ['必须包含', '不允许包含', '不限制'],
      firstIsUpper: ['必须包含', '无', '不限制']
    }
  },
  watch: {},
  computed: {},
  methods: {
    /**
     * 选择
     */
    handleSelectionChange(selection) {
      this.selectionIds = selection.map((item) => item.id)
      this.single = selection.length != 1
      this.multiple = !selection.length
    },
    /**
     * 获取列表
     */
    getList() {
      this.loading = true
      pwdrule_queryPageList({ ...this.query }).then(res => {
        if (res && res.code === 200) {
          this.list = res.rows
          this.total = res.total
        } else {
          this.handleListTips(res)
        }
      }).finally(() => {
        this.loading = false
      })
    },
    /**
     * 添加/编辑
     */
    edit(row) {
      this.$refs.editDialog.show(row ? { ...row } : {})
    }
  },
  created() {
    this.getList()
  },
  mounted() {
  }
}
</script>
<style lang="scss">

</style>
